package com.bailong.nanny.dao.impl;

import com.bailong.nanny.d.UserDao;
import com.bailong.nanny.entity.User;
import com.bailong.nanny.util.JdbcUtils;
import com.bailong.nanny.util.JdbcUtils2;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserDaoImpl implements UserDao {
    @Override
    public List<User> selectAllUser() {
        return JdbcUtils.queryList(User.class,"select * from tb_user");

//        return JdbcUtils2.queryListClazz(User.class,"select * from tb_user");
    }

    @Override
    public int deleteUser(int id) {
        return JdbcUtils.update("DELETE FROM tb_user WHERE user_id = ?",id);
    }

    @Override
    public User selectUserById(int id) {
        return JdbcUtils.queryOne(User.class,"select * from tb_user where user_id=?",id);
    }

    @Override
    public User selectUserByName(String name) {
        return null;
    }

    @Override
    public int updateUser(User user) {
        return JdbcUtils.update("update tb_user set username=?,realname=?,address=?,tel=?,pic=? where user_id=?",user.getUsername(),
        user.getRealName(),user.getAddress(),user.getTel(),user.getPic(),user.getUser_id());
    }

    @Override
    public int selectUserCount() {
        return JdbcUtils.queryCount("select count(*) from tb_user");
    }

    @Override
    public List<User> selectUserLimit(int start, int length) {
        return JdbcUtils.queryList(User.class,"select * from tb_user limit ?,?",start,length);
    }
}
